<template>
    <div class="index">
        <div class="page">
       <div class="content">
        <header >
            <a href="#" class="logo-a">
                <h1 class="logo">起点中文网</h1>
            </a>
            <nav class="sexbtn">
                <h3>
                    <a href="#" :class="[ismale?'btn-tab active':'btn-tab']" @click="ismale=true;getRankingHot();
            getRankingTime(); ">男生</a>
                </h3>
                <h3>
                    <a href="#" :class="[!ismale?'btn-tab active':'btn-tab']" @click="ismale=false;getRankingHot();
            getRankingTime(); ">女生</a>
                </h3>
            </nav>
            <div class="operate">
                <router-link to="/user" tag="span" class="iconfont icon-yonghu"></router-link>
                <!-- <span href="#" class="iconfont icon-yonghu"></span> -->
                <router-link to="/bookshelf" tag="span" class="iconfont icon-shu"></router-link>
                <!-- <span href="#" class="iconfont icon-shu"></span> -->
            </div>
        </header>
        <div class="banner">
      <div class="imgs">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(item, index) in imgs" :key="index">
            <img :src="item.src" alt="" />
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>
        <!-- <div class="banner">
            <ul>
                <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
                 <van-swipe-item tag="li" v-for="(item, index) in imgs" :key="index"> 
                     <img :src="item.src" alt="" />               
                </van-swipe-item>
                </van-swipe>
            </ul>
        </div> -->
        <router-link to="/search" tag="div" class="search">
            <div><svg t="1625995116915" class="icon myicon1" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1304" width="16" height="16"><path d="M938.64603 886.273219l-173.071777-173.074847c53.665247-63.987337 86.075401-146.400325 86.075401-236.446154 0-203.406666-164.895561-368.298134-368.301204-368.298134-203.409736 0-368.302227 164.892491-368.302227 368.298134 0 203.409736 164.892491 368.302227 368.302227 368.302227 89.246627 0 171.055864-31.767518 234.798631-84.579327l173.148525 173.148525c1.576915 1.576915 8.15575-2.443655 14.6957-8.979512l23.675212-23.675212C936.205445 894.428969 940.222945 887.850134 938.64603 886.273219zM483.347426 778.093381c-166.425404 0-301.338093-134.912689-301.338093-301.338093s134.912689-301.338093 301.338093-301.338093S784.685519 310.329884 784.685519 476.755288 649.773853 778.093381 483.347426 778.093381z" p-id="1305"></path></svg>启明1158</div>
        </router-link>
       </div>
       <div class="nav2">
           <ul>
                <router-link tag="li" to="/category">
                   <div>
                       <img src="https://qidian.gtimg.com/qdm/img/sort.3c6e2.png" alt="">
                   </div>
                   <div>分类</div>
                </router-link>              
               <router-link tag="li" to="/rank">
                <div>
                    <img src="https://qidian.gtimg.com/qdm/img/rank.7f3ea.png" alt="">
                </div>
                <div>排行榜</div>
               </router-link>
            <li>
                <div>
                    <img src="https://qidian.gtimg.com/qdm/img/free.80453.png" alt="">
                </div>
                <div>免费</div>
            </li>
            <li>
                <div>
                    <img src="https://qidian.gtimg.com/qdm/img/end.08eac.png" alt="">
                </div>
                <div>完本</div>
            </li>
            <li>
                <div>
                    <img src="https://qidian.gtimg.com/qdm/img/god.f39ac.png" alt="">
                </div>
                <div>大神</div>
            </li>
           </ul>
       </div>       
       <div class="hot">
           <div class="hot-top">
               <h3>热门小说</h3><span>起点编辑推荐</span>
           </div>
           <div class="module-slide">
                <ul>
                    <li v-for="(item,index) in booklist" :key="index">
                        <router-link :to="{path:'/detail',query:{id:item._id}}">
                        <!-- <a :href="item.booksrc"> -->
                            <img :src="'http://statics.zhuishushenqi.com'+item.cover" class="climg">
                            <div class="mtitle">{{item.title}}</div>
                            <div class="mauthor">{{item.author}}</div>
                        <!-- </a> -->
                        </router-link>
                    </li>
                </ul>
           </div>
       </div>
       <div class="line">
        <nav class="btn-group">
            <h3 class="btn-group-cell"><a>新书强推</a></h3>
            <h3 class="btn-group-cell"><a>三江，网文新风</a></h3>
        </nav>
    </div>
    <div class="hot">
           <div class="hot-top">
               <h3>现时免费</h3><span><time01 :remainTime="7200" ></time01></span>
           </div>
           <div class="module-slide">
                <ul>
                    <li v-for="(item,index) in timelist" :key="index">
                        <router-link :to="{path:'/detail',query:{id:item._id}}">
                        <!-- <a :href="item.booksrc"> -->
                            <img :src="'http://statics.zhuishushenqi.com'+item.cover" class="climg">
                            <div class="mtitle">{{item.title}}</div>
                            <div class="mauthor">{{item.author}}</div>
                        <!-- </a> -->
                        </router-link>
                    </li>
                </ul>
           </div>
       </div>
       <div class="hot">
           <div class="hot-top">
               <router-link to="/rank">
               <h3>排行榜</h3>
               <span class="iconfont icon-you fr"></span>
               </router-link>
           </div>
           <div class="ranktab">
               <ul>
                   <li v-for="(item,index) in ranklistmale" :key="index" :class="[index==ranktype?'active':'']" @click="ranktype=index">{{item.shortTitle}}</li>
               </ul>
           </div>
           <div class="module-slide">
                <ul>
                    <li v-for="(i,k) in ranklistmale[ranktype].books" :key="k" >
                        <router-link :to="{path:'/detail',query:{id:i._id}}">
                            <img :src="'http://statics.zhuishushenqi.com'+i.cover" class="climg">
                            <div class="mtitle">{{i.title}}</div>
                            <div class="mauthor">{{i.author}}</div>
                        </router-link>
                    </li>
                </ul>
           </div>
       </div>
   </div> 
    </div>
</template>
<script>
import 'vant/lib/index.css'
// import "../assets/css/index.css"
// import Axios from 'axios'
import {getRanktype,getRanking} from '../api/index.js'
// import {getRanking} from '../api/index.js'
import time01 from "../components/time.vue"
export default {
    data() {
        return {
            ismale:true,
            imgs:[
                {
                    src:require("../assets/image/banner/1.jpg")
                },
                {
                    src:require("../assets/image/banner/2.jpg")
                },
                {
                    src:require("../assets/image/banner/3.jpg")
                },
                {
                    src:require("../assets/image/banner/4.jpg")
                },
            ],
            booklist:[],
            timelist:[],
            rank:[],
            ranklistmale:[{books:[]}],
            ranktype:0,
            hotRecommend:""
        }
    },
    components:{
        time01
    },
    methods:{
        getRankingHot(){
            getRanking('54d42d92321052167dfb75e3').then(data=>{
                // console.log(data);
                if(this.ismale){
                    this.booklist=data.ranking.books.splice(0,8);
                }else{
                    this.booklist=data.ranking.books.splice(9,17);
                }
                
            })
            this.$forceUpdate();
        },
        getRankingTime(){
            getRanking('5a6844f8fc84c2b8efaa8bc5').then(data=>{
                // console.log(data);
                if(this.ismale){
                    this.timelist=data.ranking.books.splice(0,8);
                }else{
                    this.timelist=data.ranking.books.splice(9,17);
                }
            })
            this.$forceUpdate();
        },
        getRankingFun(){
            getRanktype().then(data=>{
                // console.log(data);
                let list = data.male.splice(0,4);
                list.forEach(element => {
                    getRanking(element._id).then(data=>{
                        // console.log(data);
                        element.books=data.ranking.books.splice(0,10);
                        this.$forceUpdate();
                    })
                });
                
                // this.$set(this.ranklistmale,0,list);
                
                this.ranklistmale = list
                console.log(this.ranklistmale)
                
            })
            this.$forceUpdate();
        }
    },
    created(){        
            this.getRankingHot();
            this.getRankingTime();   
            this.getRankingFun();   
    },
    
}
</script>
<style lang="less">
.index{
    .page{
    width: 100%;
    min-height: calc(100vh - 8.75rem);
    background-color: rgb(246,247,249);
}
.content{
    padding-bottom: .1px;
    background-color: #f6f7f9;
}
header{
    display: flex;
    flex-direction: row;
    padding-top: 10px;
    margin-bottom: 10px;
}
a{
    text-decoration: none;
}
.sexbtn{
    display: flex;
}
.logo-a{
    // padding: 0 1rem;
    margin-left: 1rem;
}
.logo{
    font-size: 18px;
    color: black;   
}
nav{
    margin-top: -8px;
}
header nav{
    margin-top: 0px !important;
    margin-left: 36px;
}
.btn-tab{
    font-size: .8125rem;
    
    display: block;
    line-height: 1.6875rem;
    padding: 0 .75rem !important;
    text-align: center;
    color: #ed424b;
    border: 1px solid #ed424b;
    font-weight: normal !important;
}
.sexbtn>h3:last-child>.btn-tab{
    border-radius: 0 4px 4px 0;
}
.sexbtn>h3:first-child>.btn-tab{
    border-radius: 4px 0 0 4px;
}
.active{
    color: #fff;
    background-color: #ed424b;
}
.operate{
    height: 2rem;
    display: flex;
    flex-direction: row;
    line-height: 1.5rem;
    padding: .25rem .375rem;
    margin-left: 57px;
}
.operate span{
    display: inline-block;
    height: 24px;
    width: 24px;
    margin-right: 6px;
    font-size: 16px;
    color: #ed424b;
}
.banner{
    width: 100%;
    background-color: rgb(246,247,249);
    height: 116px;
    margin-top: -10px;
}
.banner .my-swipe .van-swipe__track{
    display: flex;
}
.van-swipe__indicators{
    bottom: 80px;
}
.my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    line-height: 150px;
    text-align: center;
    /* background-color: #39a9ed; */
  }
  .banner .imgs{
      margin: 0 auto;
      min-height: 116px;
      width: 100%;
      padding: 0 12px;
    height: 100%;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
  }
.banner ul{
    padding: 0 12px;
    height: 100%;
    width: 100%;
    box-sizing: border-box;
}
.banner .my-swipe{
    min-height: 116px;
    /* height: 100%; */
    /* width: 100%; */
}
.banner .my-swipe img{
    width: 100%;
}
.search{
    width: 100%;
    height: 32px;

    display: block;
    padding: 0 .75rem;
    margin: .375rem 0;
    text-align: center;
    color: #969ba3;
    border-radius: .25rem;
    background-color: rgb(246,247,249);
    box-sizing: border-box;
}
.search div{
    text-align: center;
    font-size: .8125rem;
    line-height: 2rem;
    height: 100%;
    width: 100%;
    background-color: #fff;
}
.myicon1{
    margin-right: .3125rem;
    /* margin-top: .1rem; */
}
.nav2{
    box-sizing: border-box;
    width: 100%;
    padding: 16px 24px;
    background-color: #fff;
   font-size: 12px;
}
.nav2 ul{
    display: flex;
    flex-direction: row;
    justify-content: space-between;
}
.nav2 ul li {
    text-align: center;
}
.nav2 li img{
    width: 100%;
    height: 100%;
}
.nav2 li>div:first-child{
    height: 30px;
    width: 30px;
    margin: 0 auto;
    /* background-color: red; */
}
.hot{
    width: 100%;
    background-color: #fff;
    margin-top: 10px;
    /* height: 1.75rem; */
    padding: 0 1rem;
    border-top: 1rem solid transparent;
    box-sizing: border-box;
}
.hot h3{
    display: inline-block;
    font-family: FZZCYSK;
    font-weight: 400;
    display: inline;
    color: #33373d;
}
.hot span{
    margin-left: 6px;
    font-size: 0.85rem;
    color: rgb(150,155,163);
}
.hot h3::before{
    display: inline-block;
    box-sizing: border-box;
    width: .625rem;
    height: 1em;
    content: '';
    vertical-align: -.22ex;
    color: transparent;
    border-left: 2px solid #ed424b;
}
.line{
    margin: 1rem;
}
.btn-group{
    display: table;
    width: 100%;
    margin-right: auto;
    margin-left: auto;
    table-layout: fixed;
}
.btn-group-cell{
    font-size: 100%;
    font-weight: 400;
    display: table-cell;    
    
}
.btn-group-cell a{
    font-size: .8125rem;
    line-height: 1.6875rem;
    display: inline-block;
    padding: 0 .625rem;
    text-align: center;
    border: 1px solid red;
    border-radius: 99px;
    text-decoration: none;
    color: red;
    outline: 0;
    display: block;
    margin: 0 .5625rem;
}
.module-slide ul{
    display: block;
    /* position: relative; */
    /* display: none; */
    overflow-x: auto;
    overflow-y: hidden;
    min-height: 10.75rem;
    padding-left: .5rem;
    white-space: nowrap;
    display: flex;
    flex-direction: row;
}
.module-slide li a{
    display: block;
    // width: 4.125rem;
    padding: .75rem .5rem .5rem;
    text-decoration: none;
    color: inherit;
}
.climg{
    display: block;
    width: inherit;
    height: 5.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.mtitle{
    font-size: .8125rem;
    width: 4.125rem;
    line-height: 1.25;
    overflow: hidden;
    max-height: 2.125rem;
    margin: .5rem 0 .125rem;
    overflow-wrap:break-word;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.mauthor{
    color: #969ba3;
    font-size: .75rem;
    width: 4rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.ranktab{
    margin: .4375rem 0rem;
    ul{
            display: table;
    width: 100%;
    margin-right: auto;
    margin-left: auto;
    table-layout: fixed;
    :first-child{
            border-radius: 4px 0 0 4px !important;
    }
    :last-child{
            border-radius: 0 4px 4px 0 !important;
    }
    li.active{
            color: #fff;
            background-color: #ed424b;
    }
    li{
        display: block;
    font-size: 100%;
    font-weight: 400;
    display: table-cell;
    font-size: .8125rem;
    line-height: 1.6875rem;    
    padding: 0 .5rem;
    text-align: center;
    color: #ed424b;
    border: 1px solid #ed424b;
    }
    }
}
.fr{
    float: right;
}
}
</style>